package com.clkj.goldpartner.dao;

import com.clkj.goldpartner.pojo.Category;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;

/**
 * @author 杨阿旺
 * @date 2021-02-28 16:27
 */
@Repository
public interface CategoryMapper extends Mapper<Category> {

    /**
     * 新增商品分类
     *
     * @param category
     */
    @Update("insert into t_cl_category values(#{category_name},#{category_status},#{category_note},#{shop_id},#{parent_id},#{category_num},#{category_type}," +
            "#{category_example},#{category_describe})")
    void addCategory(Category category);

    /**
     * 获取分列列表
     *
     * @param shop_id
     * @param parent_id
     * @return
     */
    @Select("select * from t_cl_category where parent_id = #{parent_id} and shop_id =#{shop_id}")
    List<Category> listCategories(Integer shop_id, Integer parent_id);

    /**
     * 添加商品获取分类
     *
     * @param shop_id
     * @return
     */
    @Select("select * from t_cl_category where shop_id = #{shop_id} and parent_id in (select category_id from t_cl_category where parent_id != 0) ")
    List<Category> getCategories(Integer shop_id);
}
